package com.bt7274.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bt7274.exception.BusinessException;
import com.bt7274.mapper.ActivityRecordMapper;
import com.bt7274.mapper.PromotionMapper;
import com.bt7274.mapper.UserMapper;
import com.bt7274.pojo.*;
import com.bt7274.pojo.bo.ActivityRecordBO;
import com.bt7274.pojo.vo.ActivityRecordVO;
import com.bt7274.service.ActivityRecordService;
import com.bt7274.utils.PageResponse;
import jakarta.transaction.Transactional;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;

/**
 * @BelongsProject: bt7274-back
 * @BelongsPackage: com.bt7274.service.impl
 * @Author: Galland
 * @CreateTime: 2025-06-04
 * @Description: TODO
 * @Version: 1.0
 */
@Service
@RequiredArgsConstructor
public class ActivityRecordServiceImpl implements ActivityRecordService {
    private final ActivityRecordMapper activityRecordMapper;
    private final PromotionMapper promotionMapper;
    private final UserMapper userMapper;


    @Override
    public Long getParticipantCount(String promotionId) {
        QueryWrapper<ActivityRecord> wrapper = new QueryWrapper<>();
        wrapper.eq("promotion_id", promotionId);
        return activityRecordMapper.selectCount(wrapper);
    }



    /**
     * 转换为活动记录VO
     */
    private ActivityRecordVO convertToActivityRecordVO(ActivityRecord record) {
        ActivityRecordVO vo = new ActivityRecordVO();
        BeanUtils.copyProperties(record, vo);

        // 获取用户信息
        User user = userMapper.selectById(record.getUserId());
        if (user != null) {
            vo.setUsername(user.getUsername());
        }

        // 获取活动信息
        Promotion promotion = promotionMapper.selectById(record.getPromotionId());
        if (promotion != null) {
            vo.setPromotionTitle(promotion.getTitle());
            vo.setPromotionType(promotion.getType());
        }

        return vo;
    }



}
